package com.lxyk.controller.student;

import com.github.pagehelper.PageInfo;
import com.lxyk.domain.Student;
import com.lxyk.domain.StudentVO;
import com.lxyk.service.student.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;

//管理员

@Controller
@RequestMapping("/admin")
public class StudentController {

    @Autowired
    private StudentService studentService;

    //根据班级id查询学生信息
    @RequestMapping("/findByCid")
    public String findStudentByCid(Model model, Integer cid, Integer pageNum, Integer pageSize) {
        if (pageNum == null || pageNum < 0 || "".equals(pageNum)) {
            pageNum = 1;
        }
        if (pageSize == null || "".equals(pageSize)) {
            pageSize = 10;
        }
        PageInfo<StudentVO> pageInfo = studentService.findStudentByCid(cid, pageNum, pageSize);
        model.addAttribute("pageInfo", pageInfo);
        return "student_list";
    }

    //查询所有学生信息
    @RequestMapping("/findAll")
    public String findAllStudent(Model model, Integer pageNum, Integer pageSize) {
        if (pageNum == null || pageNum < 0 || "".equals(pageNum)) {
            pageNum = 1;
        }
        if (pageSize == null || "".equals(pageSize)) {
            pageSize = 10;
        }
        PageInfo<StudentVO> pageInfo = studentService.findAllStudent(pageNum, pageSize);
        model.addAttribute("pageInfo", pageInfo);
        return "student_list";
    }

}
